﻿<!-- #layout name=empty -->
<div id="main">
  <div class="block-fullscreen">
    <div class="block-visual-editor vertical">
      <iframe id="iframe" class="kb-iframe" src="about:blank" sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-pointer-lock"></iframe>
    </div>
  </div>
  <div id="components">
    <kb-media-dialog :data.sync="mediaDialogData"></kb-media-dialog>
  </div>
</div>

<script>
  function checkBrowser(lang) {
    if (lang == "zh") {
      alert(
        "暂不支持在非Chromium内核的浏览器中编辑，请使用Chrome 、Edge Chromium..."
      );
    } else {
      alert(
        "Non-Chromium kernel browsers are not currently supported, please use Google Chrome, Microsoft Edge Chromium..."
      );
    }
  }

  function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
  }

  try {
    $.ajax("/_api/User/getLanguage?SiteId=" + getQueryString("SiteId")).then(
      function(rsp) {
        if (
          navigator.userAgent.toLowerCase().indexOf("chrome") == -1 ||
          navigator.userAgent.toLowerCase().indexOf("edge") != -1
        ) {
          checkBrowser(rsp.model);
        }
        Kooboo.LanguageManager.setLang(rsp.model);
      }
    );
  } catch (error) {}

  (function() {
    Kooboo.loadJS([
      "/_Admin/Scripts/lib/lodash.min.js",
      "/_Admin/Scripts/lib/toastr.min.js",
      "/_Admin/Scripts/lib/bootstrap.min.js",
      "/_Admin/Scripts/DataCache.js",
      "/_Admin/Scripts/app.js",
      "/_Admin/Scripts/Kooboo.Route.js",
      "/_Admin/Scripts/kooboo/EventBus.js",
      "/_Admin/Scripts/kooboo/Guid.js",
      "/_Admin/Scripts/kooboo/NodeType.js",
      "/_Admin/Scripts/kooboo/LanguageManager.js",
      "/_Admin/Scripts/kooboo/DateExtend.js",
      "/_Admin/Scripts/lib/jquery.textarea_autosize.min.js",
      "/_Admin/Scripts/components/kb-media-dialog.js",
    ]);
  })();
</script>
<script type="text/javascript">
  $(function() {
    var vueInstance = new Vue({
      el: "#components",
      data: function() {
        return {
          mediaDialogData: null
        };
      }
    });

    var tinymceScript = document.createElement("script");
    tinymceScript.src =
      "\\_Admin\\Scripts\\kooboo-web-editor\\richEditor.min.js";
    var script = document.createElement("script");
    script.src = "\\_Admin\\Scripts\\kooboo-web-editor\\index.min.js";
    var iframe = document.getElementById("iframe");
    var pageUrl = getQueryString("PageUrl");
    if (pageUrl.indexOf("?") > -1) pageUrl += "&";
    else pageUrl += "?";
    pageUrl += "koobooInline=design";
    iframe.setAttribute("src", pageUrl);
    iframe.onload = function() {
      iframe.contentDocument.Kooboo = Kooboo;
      iframe.contentDocument.vueInstance = vueInstance;
      iframe.contentDocument.parentBody = document.body;
      iframe.contentDocument.__gl = __gl = {};
      iframe.contentDocument.head.appendChild(tinymceScript);

      tinymceScript.onload = function() {
        iframe.contentDocument.head.appendChild(script);
      };

      script.onload = function() {
        $(".page-loading").hide();
      };
    };
  });
</script>
